package com.zc.portal.domain.dto;

import com.zc.portal.domain.pojo.PcmcUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Set;

public class SysUser extends PcmcUser implements UserDetails {

    private Set<SysRole> roleList;
    private boolean accountNonExpired;
    private boolean accountNonLocked;
    private boolean credentialsNonExpired;

    public SysUser() {
        this.accountNonExpired = true;
        this.accountNonLocked = true;
        this.credentialsNonExpired = true;
    }

    public SysUser(String userCode, String password, Set<SysRole> roleList) {
        this.setUserCode(userCode);
        this.setPassword(password);
        this.roleList = roleList;
        this.accountNonExpired = true;
        this.accountNonLocked = true;
        this.credentialsNonExpired = true;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.getRoleList();
    }

    @Override
    public String getUsername() {
        return this.getUserCode();
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.credentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return "0".equals(this.getDisabled());
    }

    public Set<SysRole> getRoleList() {
        return this.roleList;
    }

    public void setRoleList(Set<SysRole> roleList) {
        this.roleList = roleList;
    }

    public void setAccountNonExpired(boolean accountNonExpired) {
        this.accountNonExpired = accountNonExpired;
    }

    public void setAccountNonLocked(boolean accountNonLocked) {
        this.accountNonLocked = accountNonLocked;
    }

    public void setCredentialsNonExpired(boolean credentialsNonExpired) {
        this.credentialsNonExpired = credentialsNonExpired;
    }
}
